package com.mpp.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mpp.common.result.Result;
import com.mpp.common.util.AuthContextHolder;
import com.mpp.model.entity.user.Patient;
import com.mpp.user.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName : PatientApiController  //类名
 * @Description :   //描述
 * @Author : 易嵘  //作者
 * @Date: 2022-08-19 15:35  //时间
 */
@Api(tags = "就诊人接口")
@RestController
@RequestMapping("/admin/user/patient")
public class PatientApiController {

    @Autowired
    private PatientService patientService;

    @ApiOperation(value = "列表查询")
    @GetMapping("patientPageFindAll")
    public Result patientPageFindAll(HttpServletRequest request){
        QueryWrapper<Patient> queryWrapper = new QueryWrapper();
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> byUserId = patientService.findByUserId(userId);
        return Result.ok(byUserId);
    }

    @ApiOperation(value = "根据id查询就诊人信息")
    @GetMapping("patientFindById/{id}")
    public Result patientFindById(@PathVariable Long id){
        return Result.ok(patientService.getById(id));
    }

    @ApiOperation(value = "新增就诊人")
    @PostMapping("addPatient")
    public Result addPatient(@RequestBody Patient patient){
        return patientService.save(patient)? Result.ok():Result.fail();
    }


}
